$j(document).ready(function () {
	applyValidate($("namePrefix"),"maxlength=100");
	applyValidate($("nameSuffix"),"maxlength=100");
	applyValidate($("nameFindAndReplaceOldString"),"maxlength=100");
	applyValidate($("nameFindAndReplaceNewString"),"maxlength=100");
	
	applyValidate($("salesMeasureUnitName"),"maxlength=20");
	applyValidate($("minOrderQuantity"),"maxlength=20");
	
	applyValidate($("keywords"),"maxlength=250");
	applyValidate($("keywordsPrefix"),"maxlength=100");
	applyValidate($("keywordsSuffix"),"maxlength=100");
	applyValidate($("keywordsFindAndReplaceOldString"),"maxlength=100");
	applyValidate($("keywordsFindAndReplaceNewString"),"maxlength=100");
	
	applyValidate($("shortDescription"),"maxlength=500");
	applyValidate($("shortDescriptionPrefix"),"maxlength=100");
	applyValidate($("shortDescriptionSuffix"),"maxlength=100");
	applyValidate($("shortDescriptionFindAndReplaceOldString"),"maxlength=100");
	applyValidate($("shortDescriptionFindAndReplaceNewString"),"maxlength=100");
	
	applyValidate($("fullDescription"),"maxlength=30000");
	applyValidate($("fullDescriptionPrefix"),"maxlength=200");
	applyValidate($("fullDescriptionSuffix"),"maxlength=200");
	applyValidate($("fullDescriptionFindAndReplaceOldString"),"maxlength=200");
	applyValidate($("fullDescriptionFindAndReplaceNewString"),"maxlength=200");
	
	applyValidate($("title"),"maxlength=100");
	applyValidate($("titlePrefix"),"maxlength=50");
	applyValidate($("titleSuffix"),"maxlength=50");
	applyValidate($("titleFindAndReplaceOldString"),"maxlength=50");
	applyValidate($("titleFindAndReplaceNewString"),"maxlength=50");
	
	applyValidate($("metaKeyword"),"maxlength=250");
	applyValidate($("metaKeywordPrefix"),"maxlength=100");
	applyValidate($("metaKeywordSuffix"),"maxlength=100");
	applyValidate($("metaKeywordFindAndReplaceOldString"),"maxlength=100");
	applyValidate($("metaKeywordFindAndReplaceNewString"),"maxlength=100");
	
	applyValidate($("metaDescription"),"maxlength=250");
	applyValidate($("metaDescriptionPrefix"),"maxlength=100");
	applyValidate($("metaDescriptionSuffix"),"maxlength=100");
	applyValidate($("metaDescriptionFindAndReplaceOldString"),"maxlength=100");
	applyValidate($("metaDescriptionFindAndReplaceNewString"),"maxlength=100");
	
	applyValidate($("price"),"maxlength=20");
	applyValidate($("priceNumeric"),"maxlength=20");
	applyValidate($("salePrice"),"maxlength=20");
	applyValidate($("salePriceNumeric"),"maxlength=20");
	applyValidate($("listPrice"),"maxlength=20");
	applyValidate($("listPriceNumeric"),"maxlength=20");

	applyValidate($("weight"),"maxlength=20");
	
});	


function unitiveBulkEditSave(){
	//clear the message
	$j('#message').empty();
	var confirmMsg = __FMT.common_message_confirmSaveThis+"?";
	if(validateAction()){
    	if (!confirmMsg || confirm(confirmMsg)) {
	    	var url = document.productForm.action+"?doAction=unitiveBulkEditSave";
	    	var postData = $j('#productForm :input').serialize();
			$j.post(url,postData,unitiveBulkEditSaveCallback,"json");
	    }
    }

}

function unitiveBulkEditSaveCallback(){
   sysMsg(__FMT.bulkEdit_commit_success);
}


function validateAction(){
	//set the realvalue
	KE.util.setData('fullDescription');
	//remove all the red
	$j(".x-form-invalid + img").remove();	
	$j(".x-form-invalid").attr("class","");	
	$j('input[validconf]','#productForm').each(function(i,o){
   		removeValidate(o);
   	});
	
	var flag = true;
	
	if($("nameCheck").checked && $("nameMethod2").checked)applyValidate($("namePrefix"),"maxlength=100");
	if($("nameCheck").checked && $("nameMethod2").checked)applyValidate($("nameSuffix"),"maxlength=100");
	if($("nameCheck").checked && $("nameMethod3").checked)applyValidate($("nameFindAndReplaceOldString"),"required,maxlength=100");
	if($("nameCheck").checked && $("nameMethod3").checked)applyValidate($("nameFindAndReplaceNewString"),"maxlength=100");
	
	if($("categoryCheck").checked )applyValidate($("categoryId"),"required");
	
	if($("salesMeasureUnitNameCheck").checked )applyValidate($("salesMeasureUnitName"),"maxlength=20");
	
	applyValidate($("minOrderQuantity"),"intRange=[1-100000]");
	
	if($("keywordsCheck").checked && $("keywordsMethod1").checked)applyValidate($("keywords"),"maxlength=250");
	if($("keywordsCheck").checked && $("keywordsMethod2").checked)applyValidate($("keywordsPrefix"),"maxlength=100");
	if($("keywordsCheck").checked && $("keywordsMethod2").checked)applyValidate($("keywordsSuffix"),"maxlength=100");
	if($("keywordsCheck").checked && $("keywordsMethod3").checked)applyValidate($("keywordsFindAndReplaceOldString"),"required,maxlength=100");
	if($("keywordsCheck").checked && $("keywordsMethod3").checked)applyValidate($("keywordsFindAndReplaceNewString"),"maxlength=100");
	
	
	if($("shortDescriptionCheck").checked && $("shortDescriptionMethod1").checked)applyValidate($("shortDescription"),"maxlength=500");
	if($("shortDescriptionCheck").checked && $("shortDescriptionMethod2").checked)applyValidate($("shortDescriptionPrefix"),"maxlength=100");
	if($("shortDescriptionCheck").checked && $("shortDescriptionMethod2").checked)applyValidate($("shortDescriptionSuffix"),"maxlength=100");
	if($("shortDescriptionCheck").checked && $("shortDescriptionMethod3").checked)applyValidate($("shortDescriptionFindAndReplaceOldString"),"required,maxlength=100");
	if($("shortDescriptionCheck").checked && $("shortDescriptionMethod3").checked)applyValidate($("shortDescriptionFindAndReplaceNewString"),"maxlength=100");
	
	if($("fullDescriptionCheck").checked && $("fullDescriptionMethod1").checked)applyValidate($("fullDescription"),"maxlength=30000");
	if($("fullDescriptionCheck").checked && $("fullDescriptionMethod2").checked)applyValidate($("fullDescriptionPrefix"),"maxlength=200");
	if($("fullDescriptionCheck").checked && $("fullDescriptionMethod2").checked)applyValidate($("fullDescriptionSuffix"),"maxlength=200");
	if($("fullDescriptionCheck").checked && $("fullDescriptionMethod3").checked)applyValidate($("fullDescriptionFindAndReplaceOldString"),"required,maxlength=200");
	if($("fullDescriptionCheck").checked && $("fullDescriptionMethod3").checked)applyValidate($("fullDescriptionFindAndReplaceNewString"),"maxlength=200");
	
	if($("titleCheck").checked && $("titleMethod1").checked)applyValidate($("title"),"maxlength=100");
	if($("titleCheck").checked && $("titleMethod2").checked)applyValidate($("titlePrefix"),"maxlength=50");
	if($("titleCheck").checked && $("titleMethod2").checked)applyValidate($("titleSuffix"),"maxlength=50");
	if($("titleCheck").checked && $("titleMethod3").checked)applyValidate($("titleFindAndReplaceOldString"),"required,maxlength=50");
	if($("titleCheck").checked && $("titleMethod3").checked)applyValidate($("titleFindAndReplaceNewString"),"maxlength=50");
	
	if($("metaKeywordCheck").checked && $("metaKeywordMethod1").checked)applyValidate($("metaKeyword"),"maxlength=250");
	if($("metaKeywordCheck").checked && $("metaKeywordMethod2").checked)applyValidate($("metaKeywordPrefix"),"maxlength=100");
	if($("metaKeywordCheck").checked && $("metaKeywordMethod2").checked)applyValidate($("metaKeywordSuffix"),"maxlength=100");
	if($("metaKeywordCheck").checked && $("metaKeywordMethod3").checked)applyValidate($("metaKeywordFindAndReplaceOldString"),"required,maxlength=100");
	if($("metaKeywordCheck").checked && $("metaKeywordMethod3").checked)applyValidate($("metaKeywordFindAndReplaceNewString"),"maxlength=100");
	
	if($("metaDescriptionCheck").checked && $("metaDescriptionMethod1").checked)applyValidate($("metaDescription"),"maxlength=250");
	if($("metaDescriptionCheck").checked && $("metaDescriptionMethod2").checked)applyValidate($("metaDescriptionPrefix"),"maxlength=100");
	if($("metaDescriptionCheck").checked && $("metaDescriptionMethod2").checked)applyValidate($("metaDescriptionSuffix"),"maxlength=100");
	if($("metaDescriptionCheck").checked && $("metaDescriptionMethod3").checked)applyValidate($("metaDescriptionFindAndReplaceOldString"),"required,maxlength=100");
	if($("metaDescriptionCheck").checked && $("metaDescriptionMethod3").checked)applyValidate($("metaDescriptionFindAndReplaceNewString"),"maxlength=100");
	
	if($("priceCheck").checked && $("priceMethod1").checked)applyValidate($("price"),"required,price,floatRange=[0-9999999999]");
	if($("priceCheck").checked && $("priceMethod4").checked)applyValidate($("priceNumeric"),"required,price,floatRange=[0-1000]");
	if($("salePriceCheck").checked && $("salePriceMethod1").checked)applyValidate($("salePrice"),"price,floatRange=[0-9999999999]");
	if($("salePriceCheck").checked && $("salePriceMethod4").checked)applyValidate($("salePriceNumeric"),"required,price,floatRange=[0-1000]");
	if($("listPriceCheck").checked && $("listPriceMethod1").checked)applyValidate($("listPrice"),"price,floatRange=[0-9999999999]");
	if($("listPriceCheck").checked && $("listPriceMethod4").checked)applyValidate($("listPriceNumeric"),"required,price,floatRange=[0-1000]");

	if($("wpPriceCheck").checked)flag = flag && applyValidateWholeSalePrice();
	
	if($("weightCheck").checked)applyValidate($("weight"),"floatRange=[0-100000]");
		
	if($("imageCheck").checked || $("accessoryCheck").checked){
		$j('input[name="mediaDescs"]').each(function(index,obj){
			applyValidate(obj,"maxlength=25");
		});
	}	
		
	if(flag){	
		if(!validateForm()){
	    	flag = false;
	    	alert(__vaMsg.notPass);
	    	setFocusOnTab($j('.x-form-invalid:first').parents('.ui-tabs-panel')[0].id);
	   	}
	 }  	
   	
   	
   	   
    return flag;
}
//验证批发价
function applyValidateWholeSalePrice(){
	var flag = true;
	$j('input[name="wpPrices"]').each(function(index,obj){
		applyValidate(obj,"price,required");
	});
	$j('input[name="wpMinQuantitys"]').each(function(index,obj){
		if(flag){
			if("" == obj.value.trim() || !isNotNegativeInteger(obj.value.trim())){
				problemQuantity = obj;
				setTimeout("problemQuantity.focus();", 0);//必须用这种方法才能focus住
				jAlert(__FMT.productForm_signNotNegativeNum);
				setFocusOnTab(1);
				flag = false;
			}
		}
	});
	$j('input[name="wpMaxQuantitys"]').each(function(index,obj){
		if(flag){
			if("" == obj.value.trim() || !isNotNegativeInteger(obj.value.trim())){
				problemQuantity = obj;
				setTimeout("problemQuantity.focus();", 0);//必须用这种方法才能focus住
				jAlert(__FMT.productForm_signNotNegativeNum);
				setFocusOnTab(1);
				flag = false;
			}
		}
	});
	$j('input[name="wpMaxQuantitys"]').each(function(index,obj){
		if(flag){
			var maxQuantity= obj.value;
			var temp = $j(obj).parent("td:first");
			var temp2 = $j(obj).parent("td:first").prev();
			var minQuantity= $j(obj).parent("td:first").prev().children(".minQuantity").get(0).value;
			if(!isLargerEqual(maxQuantity,minQuantity)){
				problemQuantity = obj;
				setTimeout("problemQuantity.focus();", 0);//必须用这种方法才能focus住
				jAlert(__FMT.productForm_incorrectMaxQuantity);
				setFocusOnTab(1);
				flag = false;
				
			}
		}
	});
	return flag;
}

//选择目录
function selectCategory(){
	
	showDialogOfproductCategorySelector();
}

//选择目录callback category 是一个json对象 {id，name}
function selectCategoryCallback(category){
	$j.getJSON(__ctxPath+"/product/prod/blank.html?doAction=getFullCategoryPathName&categoryId="+category.id,null,getFullCategoryPathNameCallback);
	$j('#categoryId').val(category.id);
	closeDialogOfproductCategorySelector();
	$j('#categoryId').next('img').remove();//如果有验证错误的移除
}
//根据名称获取目录全名
function getFullCategoryPathNameCallback(data){
	$j('#categoryName').html(data.fullCategoryPathName);
}

var wholesalePriceCounter=0;
//增加批发价
// tableDivId 是批发价所对应的wholesalePriceTable;
// wholesalePrice是一个JSON对象{wpId,wpSkuId,wpMinQuantity,wpMaxQuantity,wpPrice,wpDeliveryDay};
function addWholesalePrice(tableDivId,wholesalePrice){
	var id,skuId,minQuantity,maxQuantity,price,deliveryDay;
	var isFirst = true;
	var lastMaxQuantity = $j('.maxQuantity:last','#'+tableDivId);
	if(lastMaxQuantity.size() == 0){
		isFirst = true;
	}else{
		isFirst = false;
	}
	if(null == wholesalePrice){
		wholesalePriceCounter++;
		id = "new_"+wholesalePriceCounter; //new前缀表示新增
		
		
		if(!isFirst){
			//start:获得上一个最大值,并设置下一个最小值
			if(null != lastMaxQuantity && lastMaxQuantity.val()!= "" ){
				if(isNotNegativeInteger(lastMaxQuantity.val())){
					minQuantity = ""+(parseInt(lastMaxQuantity.val())+1);
				}else{
					jAlert(__FMT.productForm_signNotNegativeNum);
					lastMaxQuantity.get(0).focus();
				return;
				}	
			}else{
				jAlert(__FMT.productForm_signLastMaxQuantity);
				lastMaxQuantity.get(0).focus();
				return;
			}	
			//end:获得上一个最大值,并设置下一个最小值
			
		}else{
			minQuantity = "1";
		}	
		maxQuantity = "";
		price = "";
		deliveryDay = "";
	}else{
		id = "_"+wholesalePrice.wpId;
		minQuantity = wholesalePrice.wpMinQuantity;
		maxQuantity = wholesalePrice.wpMaxQuantity;
		price = wholesalePrice.wpPrice;
		deliveryDay = wholesalePrice.wpDeliveryDay;
	}
	var skuTr = $j('#'+tableDivId).parents(".content");
	var skuIdInput = $j('input[name="skuIds"]',skuTr);
	skuId = "wp"+skuIdInput.val();
	//将上一个的delete 链接隐藏
	var lastDelete = $j('.deleteWholesalePrice:last','#'+tableDivId);
	lastDelete.hide();
	
	var html = "";
	html += '<tr id="wholesalePrice'+id+'" >';
	if(isFirst){
		html += '<td ><input style="width:100px;" class="minQuantity inputtxt" id="wpMinQuantity'+id+'"  name="wpMinQuantitys" value="'+minQuantity+'" onchange="wpMinQuantityHandler(\''+id+'\')"/></td>';
	}else{
		html += '<td ><span>'+minQuantity+'</span><input type="hidden" class="minQuantity" id="wpMinQuantity'+id+'" name="wpMinQuantitys" value="'+minQuantity+'"/></td>';
	}
	html += '<td ><input style="width:100px;" class="maxQuantity inputtxt" id="wpMaxQuantity'+id+'" name="wpMaxQuantitys" value="'+maxQuantity+'"  onchange="wpMaxQuantityHandler(\''+id+'\')"/></td>';
	html += '<td ><input style="width:100px;" class="inputtxt" id="wpPrice'+id+'" name="wpPrices" value="'+price+'"/></td>';
	html += '<td ><a class="deleteWholesalePrice del_price" href="javascript:void(0)" onclick="delWholesalePrice(\''+tableDivId+'\',\'wholesalePrice'+id+'\')" ><b>&nbsp;</b></a></td>';
	//start:hidden
	html += '<input type="hidden" name="wpIds" id="wpId'+id+'" value="wpId'+id+'"/>';
	html += '<input type="hidden" name="wpSkuIds" id="'+skuId+'" value="'+skuId+'"/>';
	//end:hidden
	html += '</tr>';
	$j('#'+tableDivId).append(html); 
	
}
//删除批发价
// tableDivId 是批发价所对应的wholesalePriceTable;
// trDivId 是批发价所对应的wholesalePriceTr;
function delWholesalePrice(tableDivId,trDivId){
	$j('#'+trDivId).remove();
	//将上一个的delete 链接显示
    var lastDelete = $j('.deleteWholesalePrice:last','#'+tableDivId);
    lastDelete.show();
}

//改变截止购买数量的handler
var problemQuantity;  //问题所在的quantity
function wpMaxQuantityHandler(id){
	var obj = $j('.maxQuantity:last','#wholesalePrice'+id);
	if(!isNotNegativeInteger(obj.val())){
		jAlert(__FMT.productForm_signNotNegativeNum);
		obj.val("");
		problemQuantity = obj.get(0);
		setTimeout("problemQuantity.focus();", 0);//必须用这种方法才能focus住

	}else{
		var nextMinQuantity =obj.parent("td").parent("tr").next().find('.minQuantity');
		if(nextMinQuantity.size()!=0){
			nextMinQuantity.val(parseInt(obj.val())+1);
			nextMinQuantity.prev("span").html(nextMinQuantity.val());
		}
	}
}

//改变起始购买数量的handler
function wpMinQuantityHandler(id){
	var obj = $j('.minQuantity:last','#wholesalePrice'+id);
	if(!isNotNegativeInteger(obj.val())){
		jAlert(__FMT.productForm_signNotNegativeNum);
		$j(this).val("");
		problemQuantity = obj.get(0);
		setTimeout("problemQuantity.focus();", 0);//必须用这种方法才能focus住
	}else{
	}
}


var mediaId = 0;
var currentMiddleImageId;  //记录当前中图是哪个小图点击而打开的
//增加商品图片  media是一个JSON对象{mediaId,mediaDescription,mediaUrl}
function addNewProductImage(media){
	var id,mediaUrl,src_s0,src_m0,desc;
	//stat : set id,src
	
	id = "_"+media.mediaId;
	mediaUrl = media.mediaUrl;
	src_s0 = __mediaPath + mediaUrl.substring(0,mediaUrl.lastIndexOf("."))+"_s0"+mediaUrl.substring(mediaUrl.lastIndexOf("."));
	src_m0 = __mediaPath + mediaUrl.substring(0,mediaUrl.lastIndexOf("."))+"_m0"+mediaUrl.substring(mediaUrl.lastIndexOf("."));
	desc = media.mediaDescription;
	//end:
	
	var html = '';
	html += '<td class="productImageDiv" id="image'+id+'">';
	html += '<div  class="img clearfix"><a href="javascript:void(0)" onclick="showBigPict(\'mediaImage'+id+'\')">';
	html += '<img id="mediaImage'+id+'"  src="' + src_s0+ '" src_m0="'+src_m0+'" mediaUrl="'+__mediaPath+mediaUrl+'" width="50" height="50" onerror="this.src=__defaultImage;this.onerror=\'\'" /></a>';
	html += '<div class="do">';
	html += '<a href="javascript:void(0)" name="move_l" class="move_l" onclick="moveUpProductImage(this)">up</a>';
	html += '<a href="javascript:void(0)" name="del" class="del" onclick="removeProductImage(this)">delete</a>';
	html += '<a href="javascript:void(0)" name="move_r" class="move_r" onclick="moveDownProductImage(this)">down</a>';
	html += '</div></div>';
	
	//start: hidden
	html += '<input type="hidden" name="mediaUrls" value="'+media.mediaUrl+'" id="mediaUrl'+id+'"  />';
	html += '<input type="hidden" name="mediaIds" id="mediaId'+id+'" value="mediaId'+id+'"/>';
	html += '<input type="hidden" name="mediaTypes" value="0"/>';
	html += '<input type="hidden" name="mediaDescs" value=""/>';
	//end : hidden
	html += '</td>';
	
	$j('#imageList').append(html);
	$j('#image'+id).bind('mouseover',function(){$j(this).find('.do').show();}).bind('mouseout',function(){$j(this).find('.do').hide();});
	$j('#allPicsDiv').show();
	showImageMoveIcons();
	
	//如果是上传的第一幅图,则显示在主图区域
	if($j('#imageList td').length==1){
		showBigPict('mediaImage'+id);
	}
	
}


//在主图区域显示图片
function showBigPict(mediaImageId){
	$j('#productMainImageDiv').get(0).src = $j('#'+mediaImageId).attr("src_m0");
	$j("#productMainImageDiv").parent('a').attr("href",$j('#'+mediaImageId).attr("mediaUrl")).attr("target","_blank");
	currentMiddleImageId = $j('#'+mediaImageId).parents(".productImageDiv").attr("id");

}

//上传商品图片后的回调函数
function uploadProductImagehandler(mediaUrl,fileInputId){
	mediaId++;
	addNewProductImage({"mediaId":'new_'+mediaId,"mediaDescription":"","mediaUrl":mediaUrl});
}

//刷新图片区左移和右移图标是否显示
function showImageMoveIcons(){
	$j('#imageList td.productImageDiv a[name="move_l"]').addClass("move_l").removeClass("move_l_gray");
	$j('#imageList td.productImageDiv a[name="move_r"]').addClass("move_r").removeClass("move_r_gray");
	$j('#imageList td.productImageDiv:first a[name="move_l"]').addClass("move_l_gray").removeClass("move_l");
	$j('#imageList td.productImageDiv:last a[name="move_r"]').addClass("move_r_gray").removeClass("move_r");
}
//删除图片 
//linkDOM 是一个超链接对象
function removeProductImage(linkDOM){
	if (confirm(__FMT.common_message_confirmDeleteThis +"?")) {
		var jProductImage = $j(linkDOM).parents(".productImageDiv");
		if(jProductImage.attr("id") == currentMiddleImageId){
			//如果删除的小图是当前中图所放大的
			var jProductImageNextDisplay =  jProductImage.next();
			if(jProductImageNextDisplay.length==0){
				jProductImageNextDisplay = jProductImage.prev();
			}
			if(jProductImageNextDisplay.length==0){
				//如果已经没有任何图片
				$j('#productMainImageDiv').get(0).src = __defaultImage_m0;
				$j("#productMainImageDiv").parent('a').attr("href","javascript:void(0)").attr("target","");
			}else{
				//删除的图片之后或之前还有图片
				showBigPict(jProductImageNextDisplay.find('img[src_m0]').attr("id"));
			}
		}
		jProductImage.remove();
		
		showImageMoveIcons();
	}
}

//提升图片顺序
//linkDOM 是一个超链接对象
function moveUpProductImage(linkDOM){
	var me = $j(linkDOM).parents(".productImageDiv");
	var prev = me.prev(".productImageDiv");
	prev.before(me);
	showImageMoveIcons();
}
//降低图片顺序
//linkDOM 是一个超链接对象
function moveDownProductImage(linkDOM){
	var me = $j(linkDOM).parents(".productImageDiv");
	var next = me.next(".productImageDiv");
	next.after(me);
	showImageMoveIcons();
}


//增加附件  media是一个JSON对象{mediaId,mediaDescription,mediaUrl}
function addNewProductAccessory(media){
	var id,src,desc;
	//stat : set id,src
	
	id = "_"+media.mediaId;
	src = __mediaPath + media.mediaUrl;
	desc = media.mediaDescription;
	
	name = src.substring(src.lastIndexOf("/")+1);
	//end:
	
	var html = '';
	html += '<tr class="productAccesssoryDiv">';
	html += '<td><a href="'+src+'" target="_blank">'+name+'</td>';
	html += '<td><a class="up" href="javascript:void(0)" onclick="moveUpProductAccessory(this)" name="move_up"></a>';
	html += '<a class="down" href="javascript:void(0)" onclick="moveDownProductAccessory(this)" name="move_down"></a>';
	html += '<a class="del" href="javascript:void(0)" onclick="removeProductAccessory(this)"></a></td>';
	html += '<td><input class="inputtxt" type="text" style="width: 160px;" id="mediaDesc'+id+'" name="mediaDescs" value="'+desc+'" title="'+__FMT.productForm_media_title_tip+'"/></td>';
	html += '<td></td>';
	
	//start: hidden
	html += '<input type="hidden" name="mediaIds" id="mediaId'+id+'" value="mediaId'+id+'"/>';
	html += '<input type="hidden" name="mediaTypes" value="1"/>';
	html += '<input type="hidden" name="mediaUrls" value="'+((media!=null)?media.mediaUrl:'')+'" id="mediaUrl'+id+'"  />';
	//end : hidden
	
	html += '</tr>';
	$j('#accessoryList').append(html);
	showAccessoryMoveIcons();	
}

//上传商品附件后的回调函数
function uploadProductAccessoryhandler(mediaUrl,fileInputId){
	mediaId++;
	addNewProductAccessory({"mediaId":'new_'+mediaId,"mediaDescription":"","mediaUrl":mediaUrl});
}
//删除附件 
//linkDOM 是一个超链接对象
function removeProductAccessory(linkDOM){
	$j(linkDOM).parents(".productAccesssoryDiv").remove();
	showAccessoryMoveIcons();
}

//提升附件顺序
//linkDOM 是一个超链接对象
function moveUpProductAccessory(linkDOM){
	var me = $j(linkDOM).parents(".productAccesssoryDiv");
	var prev = me.prev(".productAccesssoryDiv");
	prev.before(me);
	showAccessoryMoveIcons();
}

//降低附件顺序
//linkDOM 是一个超链接对象
function moveDownProductAccessory(linkDOM){
	var me = $j(linkDOM).parents(".productAccesssoryDiv");
	var next = me.next(".productAccesssoryDiv");
	next.after(me);
	showAccessoryMoveIcons();
}

//刷新附件上下移动按钮显示
function showAccessoryMoveIcons(){
	$j('#accessoryList tr.productAccesssoryDiv a[name="move_up"]').addClass("up").removeClass("up_gray");
	$j('#accessoryList tr.productAccesssoryDiv a[name="move_down"]').addClass("down").removeClass("down_gray");
	$j('#accessoryList tr.productAccesssoryDiv:first a[name="move_up"]').addClass("up_gray").removeClass("up");
	$j('#accessoryList tr.productAccesssoryDiv:last a[name="move_down"]').addClass("down_gray").removeClass("down");
}





//判断str1是否大于str2, str1和str2都是字符串值
function isLargerEqual(str1,str2){
	return parseInt(str1)>=parseInt(str2);
}	
//是否非负整数 str是一个字符串值
function isNotNegativeInteger(str){
	var regExp = new RegExp("^(([1-9][0-9]*)|0)$");
	return regExp.test(str);
}

function setFocusOnTab(id){
	
	$j('#'+id+'-tab').addClass("ui-tabs-selected");
	$j('#'+id+'-tab').siblings().removeClass("ui-tabs-selected");
	$j('#'+id).removeClass("ui-tabs-hide");
	$j('#'+id).siblings('.ui-tabs-panel').addClass("ui-tabs-hide");
}


//返回到list
function returnToList(){
	if (opener && !opener.closed) {
	//如果是打开window的方式，使用下面代码
		window.close();
	}else if(parent){
	//如果是iframe的方式，使用下面代码
		if (parent.returnToList) 
			parent.returnToList();
	}
	
}


//刷新父窗口的产品列表
function refreshParent(){
	
	if (opener && !opener.closed) {
	//如果是打开window的方式，使用下面代码
		if (opener.refreshProductList) 
			opener.refreshProductList();
	}else if(parent){
	//如果是iframe的方式，使用下面代码
		if (parent.refreshProductList) 
			parent.refreshProductList();
	}
}
